import React, { PureComponent } from 'react';
import { Table, Icon, Pagination,Modal  } from 'antd';
import columns from './columns';
import axios from 'axios';
import api from '@api';
import style from './style.less';
export default class UserList extends PureComponent {
    state = {
        userList:[],
        pageInfo:{
            total:0,
            defaultCurrent:1,
            pageSize:10,
            current:1,
        }
    }

    constructor(props){
        super(props);
        this.state.columns = columns.call(this);
    }

    componentDidMount(){
        this.loadList();
    }

    reduceAction(text){
        if(text.count <= 0){
            Modal.warning({
                content:`次数不够了`,
                okText:`知道了`
            })
            return;
        };
        console.log(text);
    }

    loadList = ()=>{
        axios.post(api.userList).
        then(({data,data:{code,msg,list,pageInfo}})=>{
            if(code == 200){
                this.setState({
                    userList:list
                });
                this.setState({
                    pageInfo:Object.assign({},this.state.pageInfo,{
                        total:pageInfo.total
                    })
                })
            }
        }).
        catch((error)=>{

        });
    }

    pageChange = (page)=>{
        this.setState({
            pageInfo:Object.assign({},this.state.pageInfo,{
                current:page
            })
        },()=>{
            this.loadList();
        });
       
    }

    render() {

        const rowSelection = {
            onChange: (selectedRowKeys, selectedRows) => {
              console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
            },
           
          };

        return (
            <div>
                <Table size='default' columns={this.state.columns} dataSource={this.state.userList}
                    pagination={false}
                    rowSelection={rowSelection}
                />
               <div className={style.pageCon}>
                    <Pagination {...this.state.pageInfo} onChange={this.pageChange} />
               </div>
            </div>
        );
    }

}
